#include "StdAfx.hpp"
#include "LightComponents.hpp"


////////////////////////////////////////////////////////////////////////////////
// PointLightComponent

void PointLightComponent::CalcBoundingBoxFromRange( common::BOX &outBox, float range )
{
	outBox = BOX(-range, -range, -range, range, range, range);
}

PointLightComponent::PointLightComponent()
{
	ShadowMapDepthBias = 0.01f;
}

void PointLightComponent::UpdateObjectBoundingBox()
{
	SceneObject *obj = GetOwnerSceneObject();
	assert(obj);
	assert(Range >= 0.f);
	BOX box;
	CalcBoundingBoxFromRange(box, Range);
	obj->SetBoundingBox(box);
}


////////////////////////////////////////////////////////////////////////////////
// SpotLightComponent

SpotLightComponent::SpotLightComponent()
: HalfAngleInner(0.f)
, HalfAngleOuter(PI_4)
, AngleFalloffExponent(1.f)
{

}

void SpotLightComponent::UpdateObjectBoundingBox()
{
	SceneObject *obj = GetOwnerSceneObject();
	assert(obj);
	assert(Range >= 0.f && HalfAngleOuter >= 0.f);

	float width = sinf(HalfAngleOuter) * Range;
	obj->SetBoundingBox(BOX(-width, -width, 0.f, width, width, Range));
}

bool SpotLightComponent::IsVisible()
{
	return __super::IsVisible()
		&& HalfAngleOuter > FLT_EPSILON
		&& HalfAngleOuter > HalfAngleInner + FLT_EPSILON
		&& AngleFalloffExponent > FLT_EPSILON;
}
